package com.xiyu.service.controller.admin.customer;
import com.xiyu.service.vo.customer.customer.CustomerTransferInput;
import com.xiyu.service.vo.customer.customer.CustomerGetMailInfoByCustomerIdsOutput;
import com.xiyu.service.vo.customer.customer.CustomerGetMailInfoByCustomerIdsInput;
import com.xiyu.service.vo.customer.customer.CustomerCreateFollowInput;
import com.xiyu.service.vo.customer.customer.CustomerPutInPoolOutput;
import com.xiyu.service.vo.customer.customer.CustomerPutInPoolInput;
import com.xiyu.service.vo.customer.customer.CustomerSingleGetDetailOutput;
import com.xiyu.service.vo.customer.customer.CustomerUpdateInput;
import com.xiyu.service.vo.customer.customer.CustomerCreateInput;
import com.xiyu.service.vo.customer.customer.CustomerPageQueryOutput;
import com.xiyu.service.vo.customer.customer.CustomerPageQueryInput;
import org.springframework.web.bind.annotation.*;
import jakarta.annotation.Resource;
import org.springframework.validation.annotation.Validated;
import org.springframework.security.access.prepost.PreAuthorize;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.Operation;

import jakarta.validation.*;

import java.util.*;

import com.xiyu.service.framework.web.web.core.pojo.PageResult;
import com.xiyu.service.framework.web.web.core.pojo.CommonResult;
import static com.xiyu.service.framework.web.web.core.pojo.CommonResult.success;

import com.xiyu.service.framework.excel.core.util.ExcelUtils;

import com.xiyu.service.framework.operateLog.core.annotations.OperateLog;
import static com.xiyu.service.framework.operateLog.core.enums.OperateTypeEnum.*;

import com.xiyu.service.service.customer.CustomerService;
//import com.xiyu.service.vo.customer.customer.*;

@Tag(name = "客户管理")
@RestController
@RequestMapping("/customer/customer")
@Validated
public class CustomerController {

    @Resource
    private CustomerService customerService;

    @GetMapping("/page-query")
    @Operation(summary = "分页查询客户")
    public CommonResult<PageResult<CustomerPageQueryOutput>> pageQuery(@Valid CustomerPageQueryInput inputVO) {
        return success(customerService.pageQuery(inputVO));
    }

    @PostMapping("/create")
    @Operation(summary = "新增客户")
    public CommonResult<Long> create(@Valid @RequestBody CustomerCreateInput inputVO) {
        return success(customerService.create(inputVO));
    }

    @PutMapping("/update")
    @Operation(summary = "更新客户")
    public CommonResult<Boolean> update(@Valid @RequestBody CustomerUpdateInput inputVO) {
        return success(customerService.update(inputVO));
    }

    @PostMapping("/set-recycle")
    @Operation(summary = "放入回收站")
    @Parameter(name = "ids", description = "客户信息主键ID", example = "")
    public CommonResult<Boolean> setRecycle(@RequestParam("ids") List<Long> ids) {
        return success(customerService.setRecycle(ids));
    }

    @PostMapping("/restore")
    @Operation(summary = "从回收站恢复")
    @Parameter(name = "ids", description = "客户信息主键ID", example = "")
    public CommonResult<Boolean> restore(@RequestParam("ids") List<Long> ids) {
        return success(customerService.restore(ids));
    }

    @DeleteMapping("/deleted")
    @Operation(summary = "彻底删除")
    @Parameter(name = "ids", description = "客户信息主键ID", example = "")
    public CommonResult<Boolean> deleted(@RequestParam("ids") List<Long> ids) {
        return success(customerService.deleted(ids));
    }

    @GetMapping("/single-get-detail")
    @Operation(summary = "获取单个客户详情")
    @Parameter(name = "id", description = "客户信息主键ID", example = "")
    public CommonResult<CustomerSingleGetDetailOutput> singleGetDetail(@RequestParam("id") Long id) {
        return success(customerService.singleGetDetail(id));
    }

    @PostMapping("/put-in-pool")
    @Operation(summary = "放入公海")
    @PreAuthorize("@ss.hasPermission('customer:customer:putInPool')")
    public CommonResult<List<CustomerPutInPoolOutput>> putInPool(@Valid @RequestBody CustomerPutInPoolInput inputVO) {
        return success(customerService.putInPool(inputVO));
    }

    @PostMapping("/create-follow")
    @Operation(summary = "新增跟进")
    @PreAuthorize("@ss.hasPermission('customer:customer:createFollow')")
    public CommonResult<Long> createFollow(@Valid @RequestBody CustomerCreateFollowInput inputVO) {
        return success(customerService.createFollow(inputVO));
    }

    @PostMapping("/get-mail-info-by-customer-ids")
    @Operation(summary = "根据客户ID获取邮件联系人邮箱信息")
    public CommonResult<List<CustomerGetMailInfoByCustomerIdsOutput>> getMailInfoByCustomerIds(@Valid @RequestBody CustomerGetMailInfoByCustomerIdsInput inputVO) {
        return success(customerService.getMailInfoByCustomerIds(inputVO));
    }

    @PostMapping("/transfer")
    @Operation(summary = "客户移交")
    @PreAuthorize("@ss.hasPermission('customer:customer:transfer')")
    public CommonResult<Boolean> transfer(@Valid @RequestBody CustomerTransferInput inputVO) {
        return success(customerService.transfer(inputVO));
    }

}
